/*
 * @Author: your name
 * @Date: 2022-04-13 20:48:37
 * @LastEditTime: 2022-04-14 20:51:11
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \drivingTow\src\usege\usege.controller.ts
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { UsegeService } from './usege.service';
import { CreateUsegeDto } from './dto/create-usege.dto';
import { UpdateUsegeDto } from './dto/update-usege.dto';
import { ApiBearerAuth, ApiOperation, ApiParam } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { RolesGuard } from 'src/auth/role.guard';
import { selectAllPraticeDto } from 'src/practice/dto/update-practice.dto';

@Controller('usege')
export class UsegeController {
  constructor(private readonly usegeService: UsegeService) {}
  @ApiOperation({ summary: '创建教练车使用记录表' })
  @ApiBearerAuth()
  @Post('createUsege')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async createUsege(@Body() post:CreateUsegeDto){
    return await this.usegeService.createUsege(post)
  }

  @ApiOperation({ summary: '教练员查看教练车使用记录表' })
  @ApiBearerAuth()
  @Post('getUsegeByCoach')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getUsegeByCoach(@Body() post:selectAllPraticeDto,@Req() req){
    let newPost = { ...post,id:req.user.id}
    return this.usegeService.getUsegeByCoach(newPost)
  }

  @ApiOperation({ summary: '查看所有教练车使用记录表' })
  @ApiBearerAuth()
  @Post('getAllUsege')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getAllUsege(@Body() post:selectAllPraticeDto){
    return this.usegeService.getAllUsege(post)
  }

  @ApiOperation({ summary: '删除教练车使用记录表' })
  @ApiBearerAuth()
  @ApiParam({name:'id',description:'id'})
  @Post('delectUsege')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async delectUsege(@Param('id') id){
    return this.usegeService.delectUsege(id)
  }
}
